#!/bin/bash

# DATAPATH="$HOME/minioData"

# killed_ids=$(ps -axu | grep 'minio server' | grep -v grep | awk '{print $2}')
# for id in $killed_ids
# do
#         sudo kill $id
# done

# rm -rf $DATAPATH ./minio_server.log

DATA_PATH="$HOME/czyhome/minio/data"
CONFIG_PATH="$HOME/czyhome/minio/config"
MINIO_SERVER_NAME="minio"

if docker ps -a --filter "name=$MINIO_SERVER_NAME" --filter "status=running" --format "{{.Names}}" | grep -q "^$MINIO_SERVER_NAME$"
then
    echo "Docker container '$MINIO_SERVER_NAME' is running, now stop it"
    docker stop $MINIO_SERVER_NAME
fi

if docker ps -a --filter "name=$MINIO_SERVER_NAME" --filter "status=exited" --format "{{.Names}}" | grep -q "^$MINIO_SERVER_NAME$"
then
    echo "Docker container '$MINIO_SERVER_NAME' is exited, now remove it"
    docker rm $MINIO_SERVER_NAME
fi

sudo rm -rf $DATA_PATH $CONFIG_PATH